---
description: "Swift documentation for '%='"
title: "%="
layout: "default"
root: "/v5.1"
keywords: ""
---

<div class="intro-declaration"><code class="language-swift">func %=(lhs:rhs:)(lhs: inout Int, rhs: Int)</code></div><div class="discussion comment"><p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.
</p>
<p>The result has the same sign as <code>lhs</code> and has a magnitude less than
<code>rhs.magnitude</code>.</p>
<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
</code></pre>
</div><div class="intro-declaration"><code class="language-swift">func %=(lhs:rhs:)(lhs: inout Int16, rhs: Int16)</code></div><div class="discussion comment"><p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.
</p>
<p>The result has the same sign as <code>lhs</code> and has a magnitude less than
<code>rhs.magnitude</code>.</p>
<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
</code></pre>
</div><div class="intro-declaration"><code class="language-swift">func %=(lhs:rhs:)(lhs: inout Int32, rhs: Int32)</code></div><div class="discussion comment"><p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.
</p>
<p>The result has the same sign as <code>lhs</code> and has a magnitude less than
<code>rhs.magnitude</code>.</p>
<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
</code></pre>
</div><div class="intro-declaration"><code class="language-swift">func %=(lhs:rhs:)(lhs: inout Int64, rhs: Int64)</code></div><div class="discussion comment"><p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.
</p>
<p>The result has the same sign as <code>lhs</code> and has a magnitude less than
<code>rhs.magnitude</code>.</p>
<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
</code></pre>
</div><div class="intro-declaration"><code class="language-swift">func %=(lhs:rhs:)(lhs: inout Int8, rhs: Int8)</code></div><div class="discussion comment"><p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.
</p>
<p>The result has the same sign as <code>lhs</code> and has a magnitude less than
<code>rhs.magnitude</code>.</p>
<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
</code></pre>
</div><div class="intro-declaration"><code class="language-swift">func %=(lhs:rhs:)(lhs: inout UInt, rhs: UInt)</code></div><div class="discussion comment"><p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.
</p>
<p>The result has the same sign as <code>lhs</code> and has a magnitude less than
<code>rhs.magnitude</code>.</p>
<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
</code></pre>
</div><div class="intro-declaration"><code class="language-swift">func %=(lhs:rhs:)(lhs: inout UInt16, rhs: UInt16)</code></div><div class="discussion comment"><p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.
</p>
<p>The result has the same sign as <code>lhs</code> and has a magnitude less than
<code>rhs.magnitude</code>.</p>
<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
</code></pre>
</div><div class="intro-declaration"><code class="language-swift">func %=(lhs:rhs:)(lhs: inout UInt32, rhs: UInt32)</code></div><div class="discussion comment"><p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.
</p>
<p>The result has the same sign as <code>lhs</code> and has a magnitude less than
<code>rhs.magnitude</code>.</p>
<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
</code></pre>
</div><div class="intro-declaration"><code class="language-swift">func %=(lhs:rhs:)(lhs: inout UInt64, rhs: UInt64)</code></div><div class="discussion comment"><p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.
</p>
<p>The result has the same sign as <code>lhs</code> and has a magnitude less than
<code>rhs.magnitude</code>.</p>
<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
</code></pre>
</div><div class="intro-declaration"><code class="language-swift">func %=(lhs:rhs:)(lhs: inout UInt8, rhs: UInt8)</code></div><div class="discussion comment"><p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.
</p>
<p>The result has the same sign as <code>lhs</code> and has a magnitude less than
<code>rhs.magnitude</code>.</p>
<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2
</code></pre>
</div>